import { el } from "date-fns/locale";
import request from "../utils/request";
export default {
    getAllRole(pageNum, pageSize) {
        const params = {
            pageNum,
            pageSize
        }
        return request.get('/role', { params }, {
            method: "get"
        })
    },
    addRole(role) {
        return request.post('/role', role, {
            method: "post"
        })
    },
    getSpecieRole(roleName, roleKey, status, time, pageNum, pageSize) {
        const params = {
            roleName,
            roleKey,
            status,
            // 安全访问 time 数组，未选择时间时自动过滤字段
            ...(time?.[0] && { startTime: time[0] }),  // 仅当 time[0] 存在时添加 startTime
            ...(time?.[1] && { endTime: time[1] }),     // 仅当 time[1] 存在时添加 endTime
            pageNum,
            pageSize
        }
        return request.get('/role/getSpecieRole', { params }, {
            method: "get"
        })
    },
    deleteRole(id) {
        const data = { id: Array.isArray(id) ? id : [id] }; // 统一为数组格式
        let params;
        if (typeof id === "string") {
            params = {
                id: [id]
            }
        } else {
            params = {
                id: id
            }
        }
        console.log(data);
        console.log(params);
        return request.post('/role/delete', params, {
            method: "post"
        })
    },
    getEditRoleDetail(id){
        const params = {
            id
        }
        return request.get('/role/getEditRole', { params }, {
            method: "get"
        })
    },
    updateRole(role) {
        return request.put('/role', role, {
            method: "put"
        })
    },
    getRoleSelect(){
        return request.get('/role/getRoleSelect', {
            method: "get"
        })
    }
}